package korekosystem;

/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */


import java.awt.FlowLayout;

import javax.swing.JFrame;
import javax.swing.JLabel;
import javax.swing.JTextField;
import javax.swing.text.AttributeSet;
import javax.swing.text.BadLocationException;
import javax.swing.text.PlainDocument;

/**
 *
 * @author Wise_2
 */
public class JTextFieldLimit extends PlainDocument{
    
    private int limit;  
    
    public JTextFieldLimit(int limit){
        super();
        this.limit = limit;
    }
    
    public JTextFieldLimit(int limit, boolean upper){
        super();
        this.limit = limit;
    }
    
    @Override
    public void insertString(int offset, String str, AttributeSet attr) throws BadLocationException{
        if(str == null){
            return;
        }
            
        if ((getLength() + str.length()) <= limit) {
            super.insertString(offset, str, attr);
        }
    }
    
}
